#ifndef CPURANKVIEWMODEL_H
#define CPURANKVIEWMODEL_H

#include <QStandardItemModel>

struct CpuRankInfo {
    QString id;
    int pai_ming;
    QString ming_cheng;
    QString shu_zhi;
    double bai_fen_bi;

    CpuRankInfo(const QVariantMap &map);

    QVariantMap data;

    bool ext_switched;
};

class CpuRankViewModel : public QAbstractListModel
{
    Q_OBJECT
    Q_PROPERTY(QList<CpuRankInfo*> cpuRankInfos READ cpuRankInfos WRITE setCpuRankInfos NOTIFY cpuRankInfosChanged FINAL)
public:
    explicit CpuRankViewModel(QObject *parent = nullptr);

    enum CpuRankRole {
        CpuRankId = Qt::UserRole,
        CpuRankPaiMing,
        CpuRankMingCheng,
        CpuRankShuZhi,
        CpuRankBaiFenBi,

        CpuRankData,

        CpuRankExtSwitched,
    };

    void append(CpuRankInfo *newCpuRankInfo);
    void setFilter(const QString &cpu_ming_cheng);

    QList<CpuRankInfo *> cpuRankInfos() const;
    void setCpuRankInfos(const QList<CpuRankInfo *> &newCpuRankInfos);
signals:
    void cpuRankInfosChanged();
private:
    QList<CpuRankInfo *> m_cpuRankInfos;

    // QAbstractItemModel interface
public:
    QVariant data(const QModelIndex &index, int role) const override;
    bool setData(const QModelIndex &index, const QVariant &value, int role) override;
    int rowCount(const QModelIndex &parent) const override;
};


#endif // CPURANKVIEWMODEL_H
